package com.xingzhi.generate;


import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.util.ArrayUtil;
import com.xingzhi.util.FileUtils;

import java.io.File;

public class StaticGenerate {

    public static void main(String[] args) {
        String projectPath = System.getProperty("user.dir");
        File parentFile = new File(projectPath);
        String inputPath = new File(parentFile, "acm-template").getAbsolutePath();
        String outputPath = projectPath + "/code-generate-basic";
        copyFileByRecursion(inputPath, outputPath);
    }

    public static void copyFileByHutool(String inputPath, String outputPath) {
        FileUtil.copy(inputPath, outputPath, false);
    }

    public static void copyFileByRecursion(String inputPath, String outputPath) {
        File src = new File(inputPath);
        if (!src.exists()) {
            throw new IORuntimeException("源目录不存在");
        }
        String[] files = src.list();
        if (ArrayUtil.isNotEmpty(files)) {
            String destDirectoryName = new File(inputPath).getName();
            File destDirectory = new File(outputPath + "/" + destDirectoryName);
            if (!destDirectory.exists()) {
                destDirectory.mkdirs();
            }
            for (String file : files) {
                File srcFile = new File(inputPath + "/" + file);
                if (srcFile.isDirectory()) {
                    copyFileByRecursion(srcFile.getAbsolutePath(), destDirectory.getAbsolutePath());
                } else {
                    FileUtils.copyFile(srcFile.getAbsolutePath(), destDirectory.getAbsolutePath() + "/" + file);
                }
            }
        }
    }


}
